//
//  EditorDataSource.m
//  Personal Passlock
//
//  Created by 杨岑 on 5/27/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "EditorDataSource.h"
#import "EditorDataItem.h"


@implementation EditorDataSource

+ (instancetype)create
{
    return [[EditorDataSource alloc] init];
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        _itemList = [NSMutableArray array];
    }
    return self;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
    return self.itemList.count;
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    if (row >= self.itemList.count) return nil;
    
    EditorDataItem* item = self.itemList[row];

    NSTableCellView* cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:tableView];
    cellView.textField.stringValue = item.title;
    return cellView;
}

- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row
{
    return nil;
}

- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
    if ([self.delegate respondsToSelector:@selector(tableViewSelectionDidChange:)])
    {
        [self.delegate tableViewSelectionDidChange:notification];
    }
}

- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row
{
    return NO;
}

@end
